import Cookies from 'js-cookie'

const TokenKey = 'Admin-Token'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function getUserName() {
  return Cookies.get('userName')
}

export function setToken(token) {
  // 解码(data.data代表的是解析的数据)
  let jwt = require('jsonwebtoken')
  let str = jwt.decode(token)
  Cookies.set('userName', str.user_name)
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  Cookies.remove('user_name')
  return Cookies.remove(TokenKey)
}

export function getLoginType() {
  const loginType = Cookies.get('loginType')
  return parseInt(loginType)
}

export function setLoginType(loginType) {
  return Cookies.set('loginType', loginType)
}

export function removeLoginType() {
  return Cookies.remove('loginType')
}
